﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BoarAccess
{
    public class ResourceManager
    {
        private Dictionary<string, string> resources = new Dictionary<string, string>();

        public string RetrieveResource(string key)
        {
            return resources[key];
        }

        public string InsertResource(string key, string resource)
        {
            resources.Add(key, resource);
            return resource;
        }

        public string RetrieveFileResource(string filename)
        {
            if (resources.ContainsKey(filename))
                return resources[filename];
            else
            {
                Console.WriteLine("   [opening " + filename + "]");
                StreamReader streamReader = new StreamReader(filename);
                string text = streamReader.ReadToEnd();
                streamReader.Close();

                resources.Add(filename, text);
                return text;
            }
        }

        public static DateTime FromUnix(long seconds)
        {
            DateTime origin = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Local);
            return origin.AddSeconds(seconds);
        }
    }
}
